package hikari.hcomponents.physics;

import com.gooddies.wiring.Wiring;
import hikari.gui.panels.bullet.BulletSphereRigidBodyPanel;
import hikari.gui.panels.bullet.IBulletRigidBodyEditPanel;
import hikari.persistence.file.FileSection;
import java.io.IOException;
import org.swig.jirr.ISceneNode;

/**
 * @author sad
 */
public class SphereRigidBody extends IRigidBody {

    protected float radius;
    protected PhysicsData data;

    public SphereRigidBody(ISceneNode node, PhysicsData data) {
        this.data = data;
        radius = node.getBoundingBoxConst().getExtent().getLength() / 2.f;
    }

    @Override
    public IBulletRigidBodyEditPanel getEditPanel() {
        BulletSphereRigidBodyPanel editPanel = Wiring.getComponent(BulletSphereRigidBodyPanel.class);
        editPanel.init(data);
        return editPanel;
    }

    public float getRadius() {
        return radius;
    }

    public void setRadius(float radius) {
        this.radius = radius;
    }

    @Override
    public void write(FileSection section) throws IOException {
        FileSection sect = section.createNewSection("sphereRigid");
        sect.writeFloat("radius", getRadius());
        sect.close();
    }

    @Override
    public void read(FileSection section) throws IOException {
        setRadius(section.readFloat("radius"));
    }
}
